﻿//"con": ".car-show",
//"bd": "#lunbo",
//"bgimg": true,
//"ct": "#cont",
//"ctCur": "cur",
//"pre": ".car-l",
//"next": ".car-r",
//"moveTime": 500,
//"time": 5000

function FadeEffect(json){

				$(json.bd).children("li").eq(0).show();
				//初始化生成下标
				$(json.bd).children("li").each(function(index,value){

					if(json.bgimg == true){
					$(this).children("a").css({
						"background-image": "url("+$(this).data("bg")+")"
					});
					}else{
						console.log("插入图片");
					}
	
					$(json.ct).append("<li></li>");
					$(json.ct).children("li").eq(0).addClass(json.ctCur);
				});

			var num = $(json.bd).children("li").length;
			var time = json.time || 5000;
			var movetime = json.moveTime || 500;
			var index = 0;
			var key= 0;
			var timer=null;
			timer = setInterval(next,time);

			function move(){

				$(json.bd).children("li").eq(index).fadeIn(movetime).siblings().fadeOut(movetime);
				$(json.ct).children("li").eq(index).addClass(json.ctCur).siblings().removeClass(json.ctCur);
			}

			function next(){
				index++;
				if(index > num-1){
					index = 0;
				}
				move();
			
			} 

			function pre(){
				index--;
				if(index< 0){
					index = num-1;
				}
				move();
			}


			$(json.pre).on("click",function(){
				pre();
			});

			$(json.next).on("click",function(){
				next();
			});


			$(json.con).on("mouseenter",function(){
				clearInterval(timer);
			});

			$(json.con).on("mouseleave",function(){
				timer = setInterval(next,time);
			});

			$(json.ct).on("mouseenter","li",function(){
				$(this).addClass(json.ctCur).siblings().removeClass(json.ctCur);
				key = $(this).index();
				index = key;
				$(json.bd).children("li").eq(index).fadeIn(movetime).siblings().fadeOut(movetime);
			});

			}




